<?php

namespace App\Exports;

use App\Models\FsUser;
use Maatwebsite\Excel\Concerns\Exportable;
use Illuminate\Contracts\Support\Responsable;
use Maatwebsite\Excel\Concerns\FromQuery;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
class FsUserExport implements Responsable,FromQuery,WithMapping,WithHeadings,ShouldAutoSize
{
    use Exportable;

    private $fileName = 'fauser.xlsx';
    protected  $request;

    public function __construct()
    {
        set_time_limit(0);
        ini_set('memory_limit', -1);
    }

    /**
    * @return \Illuminate\Support\Collection
    */
    public function query()
    {
        $fsUser = new FsUser();
        $users = $fsUser->search($this->request,1);
        return $users;
    }


    public function condition($request){
        $this->request = $request;
        return $this;
    }

    public function headings(): array
    {
        return [
            '用户名',
            '姓名',
            '代理商',
            '注册日期',
            '存款总额',
            '存款次数',
            '提款总额',
            '提款次数',
            '单次最大存款',
            '总利润',
            '余额',
            '最后登陆时间',
            '联系电话',
        ];
    }

    public function map($FsUser): array
    {
        return [
            $FsUser->username,
            $FsUser->true_name,
            $FsUser->agent,
            $FsUser->register_time,
            $FsUser->deposit_total,
            $FsUser->deposit_count,
            $FsUser->withdrawal_total,
            $FsUser->withdrawal_count,
            $FsUser->deposit_max,
            $FsUser->deposit_total - $FsUser->withdrawal_total,
            $FsUser->balance,
            $FsUser->last_login_time,
            hidePhone($FsUser->phone_num),
        ];
    }
}
